import sys
import os, json
import requests

# sys.path.append("..")
# sys.path.append("../utils")
# os.environ.update({"DJANGO_SETTINGS_MODULE": "server.settings"})
# django.setup()
# from django.test import Client

# client = Client()
from user.tests import client

baseUrl = u"http://127.0.0.1:8000/api/software/"


def dataOperation():
    iputData = {
        "dataId": "6",
        "token": "24af9e53417b3d766552",
        "operation": '0',
    }
    res = requests.post(baseUrl + 'data/handle/', data=iputData)
    print(res.content)


def dataCheck():
    iputData = {
        "dataId": "10",
        "token": "80dd9bc3de1a768f6d41",
        "verify": '0',
        "dataResult": '',
    }
    res = requests.post(baseUrl + 'data/check/', data=iputData)
    print(res.content)


def getDataList():
    iputData = {
        'page': '1',
        'maxItem': '5',
        "token": "80dd9bc3de1a768f6d41",
        "softwareGroup": '0',
    }
    res = requests.post(baseUrl + 'material/', data=iputData)
    print(res.content)


def dataScreen():
    iputData = {
        'page': '1',
        'maxItem': '5',
        "token": "80dd9bc3de1a768f6d41",
        "keyWord": '',
        "dataCheckState": '',
        "group": '',
        "storehouseId": '3',
    }
    res = requests.post(baseUrl + 'data/screen/', data=iputData)
    print(res.content)


def getStorehouseList():
    iputData = {
        "token": "80dd9bc3de1a768f6d41",
        'page': '1',
        'maxItem': '5',
    }
    res = requests.post(baseUrl + 'storehouselist/', data=iputData)
    print(res.content)


def getTypeList():
    iputData = {
        "token": "80dd9bc3de1a768f6d41",
        'page': '1',
        'maxItem': '5',
    }
    res = requests.post(baseUrl + 'softwaretype/', data=iputData)
    print(res.content)


def dataUpdate():
    iputData = {
        "token": "83764f261b574c03be2b",
        'dataId': '6',
        'materialName': '更新资料777',
        'fileId': '',
    }
    res = requests.post(baseUrl + 'data/update/', data=iputData)
    print(res.content)


def getType():
    iputData = {
        "token": "15f3911902953e46ce92",
        'page': '1',
        'maxItem': '5',
    }
    res = requests.post(baseUrl + 'typeList/', data=iputData)
    print(res.content)


def softwareTypeOption():
    iputData = {
        "token": "15f3911902953e46ce92",
        'softwareTypeId': '1',
        'softwareTypeState': '2',
        'softwareType': '',
        'option': '2',
    }
    res = requests.post(baseUrl + 'upload/', data=iputData)
    print(res.content)


def softwareupload():
    iputData = {
        "token": "15f3911902953e46ce92",
        'softwareName': '测试更新1.0',
        'cost': '2',
        'softwareId': 20,
        'softwareDetails': '测试更新1111111111111',
        'version': '3.0',
        'storehouse': 1,
        'warZone': 1,  # ForeignKey
        'company': 1,  # ForeignKey
        'softwareType': 1,  # ForeignKey
        'logo': 69,  # address
        'cover': 70,  # address
        'verification': 78,  # address
        'fileId': 134,  # address
        'material': json.dumps([{
            'id': 132,
            'dataName': '机器学习',
        }]),
        'questionAnswer': json.dumps([{
            'id': 133,
            'dataName': '手册',
        }]),

    }
    res = requests.post(baseUrl + 'upload/', data=iputData)
    print(res.content)


def delete():
    iputData = {
        "token": "2744849f9117b8f10788",
        'id': '27',
        'option': '1'
    }
    res = requests.post(baseUrl + 'delete/', data=iputData)
    print(res.content)


def aaa():
    baseUrl1111 = u"http://192.168.6.78:10000/api/software/"
    data = {
        "token": "1a340b7cb4b16ae12dc7",
        "softwareVersionId": 39,
    }
    res = requests.post(baseUrl1111 + 'duanInfo/', data=data)
    from pprint import pprint
    pprint(res.content)

def save():
    inputData = {
        'userName': 'admin111',
    }
    res = client.post(baseUrl + 'searchUser/', inputData, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    print(res.content)

if __name__ == '__main__':
    # dataOperation()  
    # dataCheck()
    # getDataList()
    # dataScreen()
    # getStorehouseList()
    # getTypeList()
    # dataUpdate()
    # getType()
    # softwareTypeOption()
    # softwareupload()
    # delete()
    #aaa()
    save()
